/**
 * @author Steve Sedlmayr
 * @mail ssedlmayr@gmail.com
 * @link http://code.google.com/p/chitin/
 * @version 0.1
 
	The MIT License

	Copyright (c) 2009 Steve Sedlmayr

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/

package srs.chitin.mvstate.extensible 
{
	import srs.chitin.mvstate.base.OutboundEventBase;
	import srs.chitin.mvstate.base.StateChangeEventBase;
	import srs.chitin.mvstate.base.ViewBase;
	
	/** 
	 * A typed event for notification that a view's state has changed.
	 * 
	 * @eventType srs.chitin.mvstate.extensible.StateChangeEvent.STATE_CHANGE_EVENT
	 */
	[Event(name="stateChangeEvent", type="StateChangeEvent")]
	
	/** 
	 * Extensible subclass of srs.chitin.mvstate.base.ViewBase.
	 * The View portion of the truncated MVC pattern in mvstate.
	 * A subclassable Singleton.
	 */
	public class View extends ViewBase {
		/**
		 * The Singleton instance of the View class.
		 */
		private static var _instance:View;
		
		/**
		 * View class constructor. Calls <code>super()</code> on ViewBase.
		 * 
		 * @param enforcer Enforces the Singleton pattern by requiring a parameter of a type defined in, 
		 * and only visible to, instances of this class. Any other class attempting instantiation
		 * will meet with a type error. Each layer of hierarchy from ViewBase should have a corresponding
		 * enforcer class derived from ViewBaseEnforcer with the same degree of inheritance.
		 */
		public function View(enforcer:ViewEnforcer=null) : void { super(enforcer); }
		
		/**
		 * Returns the Singleton instance for the View class. 
		 * 
		 * @return The Singleton instance for the View class. 
		 */
		public static function getInstance() : View {
			if ( _instance == null ) {
				_instance = new View(new ViewEnforcer());
				_instance._context = Context.getInstance();
			}
			
			return _instance;
		}
		
		/** 
		 * Hides the view. The specific implementation is up to the concrete implementing class.
		 * Hiding could mean setting visible to false, setting alpha to 0 or some other value,
		 * or performing an animation, for instance. This method implements the IViewState interface
		 * used by ViewState but is not to be confused with the State pattern. It can be used as a
		 * pass-through to wrap the State pattern <code>hide()</code> method call if that is desired, 
		 * but is more likely to be used by a parent to control the entire view.
		 * 
		 * @param targetView The view to target the hide operation on in the concrete subclass instance.
		 * Usually the current view.
		 * 
		 * @param targetState (OPTIONAL) A state, most likely the next state to be shown, on which to
		 * perform operations associated with hiding the current view. 
		 */
		override public function hide(targetView:ViewBase, targetState:String=null) : void {}
		
		/** 
		 * Shows the view. The specific implementation is up to the concrete implementing class.
		 * Showing could entail setting visibility or simply enacting a behavior. Not to be confused
		 * with the implementation for the State pattern, which employs IViewState via the context.
		 * 
		 * @param targetView The view to target the show operation on in the concrete subclass instance; 
		 * mostly likely the current view.
		 */
		override public function show(targetView:ViewBase) : void {}
		
		/**
		 * Handle outbound events from a model or models. The specific implementation is up to the concrete implementing class.
		 * 
		 * @param event An outbound event to fire out to a listener.
		 */
		override protected function outboundEventHandler(event:OutboundEventBase) : void {}
		
		/** 
		 * Handle state change events from a view or views. The specific implementation is up to the concrete implementing class.
		 * 
		 * @param event A state change event firing from a child view.
		 */
		override protected function stateChangeEventHandler(event:StateChangeEventBase) : void {}
	}
}